package gen.kaynak.navitrack.messageProcessState;

import gen.kaynak.navitrack.messageProcessStrategy.*;

public class DegreeFractionalProcessing extends ACMessageProcessState {
	private static DegreeFractionalProcessing state = new DegreeFractionalProcessing();
	private MessageProcessStrategyManager objCLLP;

	private DegreeFractionalProcessing() {

	}

	public static ACMessageProcessState Instance() {
		return state;
	}

	@Override
	void ProcessWhiteSpace(char c, MessageProcessStateManager mpm) {
		objCLLP = new MessageProcessStrategyManager(
				new SignExistenceCheckProcessor());
		if (objCLLP.Process(c, mpm)) {
			mpm.calculateCoordinate();
			ChangeState(mpm, CoordinateDiscovered.Instance());
		} else {
			ChangeState(mpm, SecondDiscovered.Instance());
		}

	}

	@Override
	void ProcessLetter(char c, MessageProcessStateManager mpm) {
		objCLLP = new MessageProcessStrategyManager(
				new SignExistenceCheckWithLetterProcessor());
		if (objCLLP.Process(c, mpm)) {
			mpm.calculateCoordinate();
			ChangeState(mpm, CoordinateDiscovered.Instance());
		} else {
			objCLLP = new MessageProcessStrategyManager(
					new AlternationCheckWithLetterProcessor());
			if (objCLLP.Process(c, mpm)) {
				mpm.setSign("+");
				mpm.calculateCoordinate();
				ChangeState(mpm, CoordinateDiscovered.Instance());

				if (mpm.alternateProcessing()) {
					ChangeState(mpm, Initial.Instance());
					objCLLP = new MessageProcessStrategyManager(
							new NSEWProcessor());
					if (objCLLP.Process(c, mpm)) {
						ChangeState(mpm, NSEWDiscovered.Instance());
					}
				} else {
					mpm.terminateProcessManager();
					// Exit Sub
				}

			} else {
				ChangeState(mpm, SecondDiscovered.Instance());
			}

		}

	}

	@Override
	void ProcessPunctuation(char c, MessageProcessStateManager mpm) {
		objCLLP = new MessageProcessStrategyManager(
				new SignExistenceCheckProcessor());
		if (objCLLP.Process(c, mpm)) {
			mpm.calculateCoordinate();
			ChangeState(mpm, CoordinateDiscovered.Instance());
		} else {
			ChangeState(mpm, SecondDiscovered.Instance());
		}

	}

	@Override
	void ProcessSymbol(char c, MessageProcessStateManager mpm) {
		objCLLP = new MessageProcessStrategyManager(
				new SignExistenceCheckWithSymbolProcessor());
		if (objCLLP.Process(c, mpm)) {
			mpm.calculateCoordinate();
			ChangeState(mpm, CoordinateDiscovered.Instance());
		} else {
			mpm.setSign("+");
			mpm.calculateCoordinate();
			ChangeState(mpm, CoordinateDiscovered.Instance());
			if (mpm.alternateProcessing()) {
				switch (c) {
				case '+':
					ChangeState(mpm, Initial.Instance());
					mpm.setSign("+");
					ChangeState(mpm, NSEWDiscovered.Instance());
				case '-':
					ChangeState(mpm, Initial.Instance());
					mpm.setSign("-");
					ChangeState(mpm, NSEWDiscovered.Instance());
				default:
					ChangeState(mpm, Initial.Instance());
				}
			} else {
				mpm.terminateProcessManager();
				// Exit Sub
			}

		}

	}

	@Override
	void ProcessNumber(char c, MessageProcessStateManager mpm) {
		mpm.appendChar(c);
	}

}
